<div class="page-header">
    <h1>
        用户信息列表
        <small>
            <i class="ace-icon fa fa-angle-double-right"></i>
        </small>
    </h1>
</div>
<div class="row">
    <div class="col-xs-12">
        <table id="dtpList" class="dataTable">
            <tfoot>
            <tr>
                <td colspan="4">本页合计：</td>
                <td>
                    <span name="Coin" class="tooltip-"/>
                </td>
                <td>
                    <span name="Beans" class="tooltip-"/>
                </td>
                <td colspan="10"></td>
            </tr>
            </tfoot>
        </table>
        <div id="dtpList_filter" class="dataTables_filter">
            <div>
                <select id="dtpList_F_SType" class="selectpicker" data-style="btn btn-info btn-sm" data-width="90px">
                    <option value="">模糊查询</option>
                    <option data-divider="true"></option>
                    <option value="User_ID">用户ID</option>
                    <option value="NickName">用户昵称</option>
                    <option value="RealName">真实姓名</option>
                    <option value="IDCard">身份证号</option>
                    <option value="Email">Email</option>
                    <option value="Phone">手机号</option>
                    <option value="QQ">QQ号</option>
                    <option value="Channel_ID">渠道ID</option>
                    <option value="Inviter_ID">邀请人ID</option>
                    <option value="SignUp_Anchor_ID">转化房间ID</option>
                    <option value="SignUp_Anchor_Family_ID">转化公会ID</option>
                </select>
                <input id="dtpList_F_SValue" class="fvalue" type="text"/>
                <select id="dtpList_F_DateType">
                    <option value="Create_Date">注册时间</option>
                    <option value="IDCard_Date">实名时间</option>
                    <option value="Charge_First_Date">首充时间</option>
                    <option value="Charge_Last_Date">取后充值</option>
                </select>
                <input id="dtpList_F_StartDate" type="text" style="width: 76px;" placeholder="开始时间">
                <label>-</label>
                <input id="dtpList_F_EndDate" type="text" style="width: 76px;" placeholder="结束时间">
                <select id="dtpList_F_SelectDate"></select>
                <label><input id="dtpList_F_OAuthPhone" type="checkbox"/>&nbsp;验证手机</label>
                <label><input id="dtpList_F_OAuthQQ" type="checkbox"/>&nbsp;QQ</label>
                <label><input id="dtpList_F_OAuthWeixin" type="checkbox"/>&nbsp;微信</label>
                <label><input id="dtpList_F_OAuthWeibo" type="checkbox"/>&nbsp;微博</label>
                <label>状态：</label>
                <select id="dtpList_F_Status">
                    <option value="-1">所有</option>
                    <option value="0" selected="selected">正常</option>
                    <option value="1">锁定</option>
                </select>
                <a id="dtpList_F_Advanced"></a>
                <button id="dtpList_F_Btn"></button>
            </div>
            <div>
                <label>注册源：</label>
                <select id="dtpList_F_SignUpOrigin">
                    <option value="">所有</option>
                    <option value="0">PC</option>
                    <option value="100">Android</option>
                    <option value="300">iOS</option>
                </select>
                <label>实名：</label>
                <select id="dtpList_F_IDCardStatus">
                    <option value="">所有</option>
                    <option value="0">已实名</option>
                    <option value="-1,1,2">未实名</option>
                </select>
                <label><input id="dtpList_F_ChargeFirst" type="checkbox"/>&nbsp;首充</label>
                <label><input id="dtpList_F_IsVIP" type="checkbox"/>&nbsp;VIP</label>
                <label><input id="dtpList_F_IsAnchor" type="checkbox"/>&nbsp;艺人</label>
                <label><input id="dtpList_F_IsFamily" type="checkbox"/>&nbsp;公会</label>
                <label><input id="dtpList_F_IsAdmin" type="checkbox"/>&nbsp;管理员</label>
                <label>性别：</label>
                <select id="dtpList_F_Sex">
                    <option value="-1">所有</option>
                    <option value="1">男</option>
                    <option value="2">女</option>
                </select>
            </div>
        </div>
    </div>
</div>
<script src="<%- Virtual_Path.Static %>jquery.plugin/dataTables/jquery.dataTables.min.js"></script>
<script src="<%- Virtual_Path.Static %>jquery.plugin/dataTables/jquery.dataTables.bootstrap.min.js"></script>
<script>
    $(function () {
        //region 时间输入框插件
        $('#dtpList_F_StartDate, #dtpList_F_EndDate').datetimepicker({
            language: 'zh-CN',
            format: 'yyyy-mm-dd',
            minView: 2,
            autoclose: true
        });
        //endregion
        //region 绑定日期选择框
        $.KOC.Date.Select.Bind({
            eSelect: $('#dtpList_F_SelectDate'),
            eBegin: $('#dtpList_F_StartDate'),
            eEnd: $('#dtpList_F_EndDate')
        });
        //endregion
        //region dtpList
        var _dtpList = $("#dtpList").dataTable({
            'aoColumns': [
                {
                    'sWidth': '75px', 'data': 'User_ID', 'sName': 'User_ID', 'sTitle': 'ID', 'sClass': 'center',
                    'createdCell': function (td, cellData) {
                        $(td).html($('<a/>').attr('data-openwindow', ':UserInfo:' + cellData).text(cellData));
                    }
                },
                {
                    'data': 'NickName', 'sName': 'EXP', 'sTitle': '昵称',
                    'createdCell': function (td, cellData, rowData) {
                        $(td).html('<span class="Level_User_' + rowData.Level + '"></span>' + cellData);
                    }
                },
                {
                    'sWidth': '32px', 'data': 'VIP', 'sTitle': 'V', 'sClass': 'center', 'bSortable': false,
                    'createdCell': function (td, cellData, rowData) {
                        $(td).html(cellData ? '<i class="fa fa-check-square bigger-120 green" data-rel="tooltip" data-html="true" data-original-title="有效天数：' + rowData.VIP_ExpireDay + ' 天<br/>到期时间：' + moment(rowData.VIP_Expire).format('YYYY/MM/DD') + '" />' : '');
                    }
                },
                {
                    'sWidth': '32px', 'data': 'IDCard_Status', 'sTitle': '实', 'sClass': 'center', 'bSortable': false,
                    'createdCell': function (td, cellData, rowData) {
                        switch (cellData) {
                            case 0:
                                $(td).html('<i class="fa fa-check-square bigger-120 green" data-rel="tooltip" data-original-title="实名通过时间：' + moment(rowData.IDCard_Date).format('YY/MM/DD HH:mm') + '" />');
                                break;
                            case 1:
                                $(td).html('<i class="fa fa-clock-o bigger-120" data-rel="tooltip" data-original-title="等待实名审核" />');
                                break;
                            case 2:
                                $(td).html('<i class="fa fa-ban bigger-120 red" data-rel="tooltip" data-original-title="实名审核驳回" />');
                                break;
                            case -1:
                                $(td).text('');
                                break;
                            default:
                                $(td).html('<i class="fa fa-question bigger-120" data-rel="tooltip" data-original-title="未知状态" />');
                                break;
                        }
                    }
                },
                {
                    'sWidth': '8%', 'data': 'Coin', 'sName': 'Coin', 'sTitle': '金币', 'sClass': 'center t-right',
                    'createdCell': function (td, cellData) {
                        if (cellData > 0) {
                            $(td).html('<span class="tooltip-" data-rel="tooltip" data-original-title="帐户金币价值：' + $.KOC.String.ToCurrencyPositiveStr(cellData / 1000) + '">' + cellData + '</span>');
                        }
                    }
                },
                {
                    'sWidth': '7%', 'data': 'Beans', 'sName': 'Beans', 'sTitle': '金豆', 'sClass': 'center t-right',
                    'createdCell': function (td, cellData) {
                        if (cellData > 0) {
                            $(td).html('<span class="tooltip-" data-rel="tooltip" data-original-title="帐户金豆价值：' + $.KOC.String.ToCurrencyPositiveStr(cellData / 1000) + '">' + cellData + '</span>');
                        }
                    }
                },
                {
                    'sWidth': '32px', 'data': 'Charge_First', 'sTitle': '充', 'sClass': 'center', 'bSortable': false,
                    'createdCell': function (td, cellData, rowData) {
                        $(td).html(cellData ? '<i class="fa fa fa-check-square bigger-120 green" data-rel="tooltip" data-html="true" data-original-title="首充时间：' + moment(rowData.Charge_First_Date).format('YY/MM/DD HH:mm') + '<br/>最后充值：' + moment(rowData.Charge_Last_Date).format('YY/MM/DD HH:mm') + '" />' : '');
                    }
                },
                {
                    'sWidth': '110px', 'data': null, 'sTitle': '高级角色', 'sClass': 'center', 'bSortable': false,
                    'createdCell': function (td, cellData, rowData) {
                        var _html = '';
                        if (rowData.IsAnchor) {
                            _html += '<span class="label label-sm label-success middle" data-rel="tooltip" data-original-title="艺人">艺</span> ';
                        }
                        if (rowData.IsFamily) {
                            _html += '<span class="label label-sm label-info middle" data-rel="tooltip" data-original-title="公会">家</span> ';
                        }
                        if (rowData.IsAdmin) {
                            _html += '<span class="label label-sm label-danger middle" data-rel="tooltip" data-original-title="管理员">管</span> ';
                        }
                        $(td).html(_html);
                    }
                },
                {
                    'sWidth': '100px', 'data': null, 'sTitle': '登录方式', 'sClass': 'center', 'bSortable': false,
                    'createdCell': function (td, cellData, rowData) {
                        var _html = '';
                        if (rowData.OAuth_Phone) {
                            _html += '<i class="fa fa-phone-square bigger-120" data-rel="tooltip" data-original-title="手机验证" /> ';
                        }
                        if (rowData.OAuth_QQ) {
                            _html += '<i class="fa fa-qq bigger-120 text-primary" data-rel="tooltip" data-original-title="QQ绑定" /> ';
                        }
                        if (rowData.OAuth_Weixin) {
                            _html += '<i class="fa fa-weixin bigger-120 text-success" data-rel="tooltip" data-original-title="微信绑定" /> ';
                        }
                        if (rowData.OAuth_Weibo) {
                            _html += '<i class="fa fa-weibo bigger-120 text-danger" data-rel="tooltip" data-original-title="微博绑定" /> ';
                        }
                        $(td).html(_html);
                    }
                },
                {
                    'sWidth': '9%', 'data': 'Channel_ID', 'sName': 'Channel_ID', 'sTitle': '渠道ID', 'sClass': 'center'
                },
                {
                    'sWidth': '35px', 'data': 'SignUp_Origin', 'sTitle': '源', 'sClass': 'center', 'bSortable': false,
                    'createdCell': function (td, cellData) {
                        switch (cellData) {
                            case 0:
                                $(td).html('<i class="fa fa-desktop bigger-120" data-rel="tooltip" data-original-title="PC端注册" />');
                                break;
                            case 100:
                                $(td).html('<i class="fa fa-android bigger-120" data-rel="tooltip" data-original-title="Android端注册" />');
                                break;
                            case 300:
                                $(td).html('<i class="fa fa-apple bigger-120" data-rel="tooltip" data-original-title="iOS端注册" />');
                                break;
                            default:
                                $(td).html('<i class="fa fa-question bigger-120" data-rel="tooltip" data-original-title="未知" />');
                                break;
                        }
                    }
                },
                {
                    'sWidth': '35px', 'data': 'Inviter_ID', 'sName': 'Inviter_ID', 'sTitle': '邀', 'sClass': 'center', 'bSortable': false,
                    'createdCell': function (td, cellData) {
                        $(td).html(cellData > 0 ? $('<a/>').attr('data-openwindow', ':UserInfo:' + cellData).html('<i class="fa fa-check-square bigger-120 green" data-rel="tooltip" data-original-title="邀请人ID：' + cellData + '" />') : '');
                    }
                },
                {
                    'sWidth': '70px', 'data': 'SignUp_Anchor_ID', 'sName': 'SignUp_Anchor_ID', 'sTitle': '转化', 'sClass': 'center',
                    'createdCell': function (td, cellData) {
                        $(td).html(cellData > 0 ? $('<a/>').attr('data-openwindow', ':UserInfo:' + cellData).text(cellData) : '');
                    }
                },
                {
                    'sWidth': '9%', 'data': 'Create_Date', 'sName': 'User_ID', 'sTitle': '创建日期', 'sClass': 'center',
                    'createdCell': function (td, cellData) {
                        $(td).text(moment(cellData).format('YY/MM/DD HH:mm'));
                    }
                },
                {
                    'sWidth': '7%', 'data': 'Login_This_Date', 'sName': 'Login_This_Date', 'sTitle': '最近登录', 'sClass': 'center',
                    'createdCell': function (td, cellData) {
                        $(td).text(cellData ? moment(cellData).fromNow() : '');
                    }
                },
                {
                    'sWidth': '65px', 'data': 'Status', 'sName': 'Status', 'sTitle': '状态', 'sClass': 'center',
                    'createdCell': function (td, cellData) {
                        switch (cellData) {
                            case 0:
                                $(td).html('<span class="label label-success">正常</span>');
                                break;
                            case 1:
                                $(td).html('<span class="label label-danger">锁定</span>');
                                break;
                            default:
                                $(td).html('<span class="label label-default">未知</span>');
                                break;
                        }
                    }
                }
            ],
            'aaSorting': [0, 'desc'],
            'sAjaxSource': '/ajax/user.page.userinfo',
            'fnServerParams': function (aoData) {
                if (!this.arrPageFilter) {
                    this.arrPageFilter = {
                        F_DateType: $(this.selector + '_F_DateType').val(),
                        F_StartDate: $(this.selector + '_F_StartDate').val(),
                        F_EndDate: $(this.selector + '_F_EndDate').val(),
                        F_OAuthPhone: $(this.selector + '_F_OAuthPhone').is(':checked') ? 1 : -1,
                        F_OAuthQQ: $(this.selector + '_F_OAuthQQ').is(':checked') ? 1 : -1,
                        F_OAuthWeixin: $(this.selector + '_F_OAuthWeixin').is(':checked') ? 1 : -1,
                        F_OAuthWeibo: $(this.selector + '_F_OAuthWeibo').is(':checked') ? 1 : -1,
                        F_SignUpOrigin: $(this.selector + '_F_SignUpOrigin').val(),
                        F_Sex: $(this.selector + '_F_Sex').val(),
                        F_IDCardStatus: $(this.selector + '_F_IDCardStatus').val(),
                        F_ChargeFirst: $(this.selector + '_F_ChargeFirst').is(':checked') ? 1 : -1,
                        F_IsVIP: $(this.selector + '_F_IsVIP').is(':checked') ? 1 : -1,
                        F_IsAnchor: $(this.selector + '_F_IsAnchor').is(':checked') ? 1 : -1,
                        F_IsFamily: $(this.selector + '_F_IsFamily').is(':checked') ? 1 : -1,
                        F_IsAdmin: $(this.selector + '_F_IsAdmin').is(':checked') ? 1 : -1,
                        F_Status: $(this.selector + '_F_Status').val()
                    };
                } else {
                    $(this.selector + '_F_DateType').val(this.arrPageFilter.F_DateType);
                    $(this.selector + '_F_StartDate').val(this.arrPageFilter.F_StartDate);
                    $(this.selector + '_F_EndDate').val(this.arrPageFilter.F_EndDate);
                    $(this.selector + '_F_OAuthPhone').prop('checked', this.arrPageFilter.F_OAuthPhone == 1);
                    $(this.selector + '_F_OAuthQQ').prop('checked', this.arrPageFilter.F_OAuthQQ == 1);
                    $(this.selector + '_F_OAuthWeixin').prop('checked', this.arrPageFilter.F_OAuthWeixin == 1);
                    $(this.selector + '_F_OAuthWeibo').prop('checked', this.arrPageFilter.F_OAuthWeibo == 1);
                    $(this.selector + '_F_SignUpOrigin').val(this.arrPageFilter.F_SignUpOrigin);
                    $(this.selector + '_F_Sex').val(this.arrPageFilter.F_Sex);
                    $(this.selector + '_F_IDCardStatus').val(this.arrPageFilter.F_IDCardStatus);
                    $(this.selector + '_F_ChargeFirst').prop('checked', this.arrPageFilter.F_ChargeFirst == 1);
                    $(this.selector + '_F_IsVIP').prop('checked', this.arrPageFilter.F_IsVIP == 1);
                    $(this.selector + '_F_IsAnchor').prop('checked', this.arrPageFilter.F_IsAnchor == 1);
                    $(this.selector + '_F_IsFamily').prop('checked', this.arrPageFilter.F_IsFamily == 1);
                    $(this.selector + '_F_IsAdmin').prop('checked', this.arrPageFilter.F_IsAdmin == 1);
                    $(this.selector + '_F_Status').val(this.arrPageFilter.F_Status);
                }
                this.ofnServerParams(aoData);
            },
            'fnFooterCallback': function (nFoot, aData) {
                var _FooterData = {
                    Coin: 0,
                    Beans: 0
                };
                _.forEach(aData, function (ThisValue) {
                    _FooterData.Coin += ThisValue.Coin;
                    _FooterData.Beans += ThisValue.Beans;
                });
                $(nFoot).find('[name="Coin"]').attr({
                    'data-rel': 'tooltip',
                    'data-original-title': '金币价值总计：' + $.KOC.String.ToCurrencyPositiveStr(_FooterData.Coin / 1000)
                }).text(_FooterData.Coin);
                $(nFoot).find('[name="Beans"]').attr({
                    'data-rel': 'tooltip',
                    'data-original-title': '金豆价值总计：' + $.KOC.String.ToCurrencyPositiveStr(_FooterData.Beans / 1000)
                }).text(_FooterData.Beans);
            },
            'fnDrawCallback': function () {
                $.Common.Bootstrap.Tooltip(this);
                this.ofnDrawCallback();
            },
            'selectOpt': {
                Tools: {
                    Init: true,
                    Buttons: {
                        'btn-Info': {
                            text: '<i class="fa fa-search"></i> 查看用户信息',
                            style: 'primary',
                            addClass: 'btn disabled',
                            'data-permission-code': '{User}[Base](Info)',
                            action: function () {
                                $.CommonAdmin.OpenWindow(':UserInfo:' + _dtpList.selectData.User_ID, function () {
                                    _dtpList.fnDraw();
                                });
                                return false;
                            }
                        },
                        'btn-Anchor': {
                            text: '查看艺人信息',
                            style: 'primary',
                            addClass: 'btn disabled',
                            'data-permission-code': '{User}[Anchor](Info)',
                            action: function () {
                                $.CommonAdmin.OpenWindow(':UserAnchorInfo:' + _dtpList.selectData.User_ID, function () {
                                    _dtpList.fnDraw();
                                });
                                return false;
                            }
                        },
                        'btn-Family': {
                            text: '查看公会信息',
                            style: 'primary',
                            addClass: 'btn disabled',
                            'data-permission-code': '{User}[Family](Info)',
                            action: function () {
                                $.CommonAdmin.OpenWindow(':FamilyInfo:' + _dtpList.selectData.Family_ID, function () {
                                    _dtpList.fnDraw();
                                });
                                return false;
                            }
                        },
                        'btn-Admin': {
                            text: '查看管理员信息',
                            style: 'primary',
                            addClass: 'btn disabled',
                            'data-permission-code': '{User}[Admin](Info)',
                            action: function () {
                                $.CommonAdmin.OpenWindow(':UserAdminInfo:' + _dtpList.selectData.User_ID, function () {
                                    _dtpList.fnDraw();
                                });
                                return false;
                            }
                        },
                        'btn-Edit': {
                            text: '<i class="fa fa-pencil"></i> 修改用户信息',
                            style: 'primary',
                            addClass: 'btn disabled',
                            'data-permission-code': '{User}[Base](Edit)',
                            action: function () {
                                $.CommonAdmin.OpenWindow(':UserEdit:' + _dtpList.selectData.User_ID, function () {
                                    _dtpList.fnDraw();
                                });
                                return false;
                            }
                        },
                        'btn-close': {}
                    },
                    onBuild: function (content) {
                        $.CommonAdmin.Permission.CheckElement(content);
                    },
                    onReset: function () {
                        if (!_dtpList.selectData) {
                            return;
                        }
                        var _btn = ['btn-Info', 'btn-Edit'];
                        if (_dtpList.selectData.IsAnchor) {
                            _btn.push('btn-Anchor');
                        }
                        if (_dtpList.selectData.IsFamily) {
                            _btn.push('btn-Family');
                        }
                        if (_dtpList.selectData.IsAdmin) {
                            _btn.push('btn-Admin');
                        }
                        _dtpList.ofnSelectToolsBtnRemoveClass(_btn);
                    }
                }
            }
        });
        //endregion
    });
</script>